#include <bits/stdc++.h>

using namespace std;
#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    int passThePillow(int n, int time)
    {
        int pos = time % (n - 1);
        int count = time / (n - 1);
        if ((count + 1) % 2)
        {
            return pos + 1;
        }
        else
        {
            return n - pos;
        }
    }
};